<?php

namespace App\Http\Controllers\Miniprograme;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class TemplateController extends ComController
{
    ///usr/local/opt/php@7.4
    //获取模板消息列表
    public function getList($offset=0, $count=5){
        return $this->miniProgram->template_message->list($offset, $count);
    }
    //获取模板库某个模板标题下关键词库
    public function get($id){
        return $this->miniProgram->template_message->get($id);
    }
    //组合模板并添加至帐号下的个人模板库
    public function add($id, $keywordIdList){
        return $this->miniProgram->template_message->add($id, $keywordIdList);
    }
    //组合模板并添加至帐号下的个人模板库
    public function getTemplates($offset, $count){
        return $this->miniProgram->template_message->getTemplates($offset, $count);
    }
    //删除帐号下的某个模板
    public function delete($templateId){
        return $this->miniProgram->template_message->delete($templateId);
    }
    //发送模板消息
    public function sendTemplate($request,$formId,$data){
        $this->miniProgram->template_message->send([
            'touser' => $request->user_openid,
            'template_id' => $request->template_id,
            'page' => $request->index,
            'form_id' => $formId,
            'data' => $data
//                [
//                'keyword1' => 'VALUE',
//                'keyword2' => 'VALUE2',
//                // ...
//            ],
        ]);
    }

}
